package com.yinhd.study.designPatterns.simpleFactory;

import java.lang.reflect.InvocationTargetException;

public class VideoFactory {
//    public Video getVideo(String type){
//         if ("java".equalsIgnoreCase(type)){
//             return new JavaVideo();
//         }else if("python".equalsIgnoreCase(type)){
//             return new PythonVideo();
//         }
//         return  null;
//    }

    //通过反射弥补简单工厂 不符合开闭原则
    public Video getVideo(Class c){

     Video video = null;
        try {
             video = (Video)c.getDeclaredConstructor().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return video;
    }
}
